<!--回复列表-->
{include file="public/header"}

<div class="content">
	<div class="page-inner">
		<div class="row">
			<div class="col-md-12">
				<div class="card">
					<div class="card-header">
						<div class="card-title">任务列表</div>
					</div>
					<div class="card-body">

						<table class="table mt-3">
							<thead>
								<tr>
									<th scope="col">id</th>
									<th scope="col">消息模板</th>
									<th scope="col">chat_title</th>
									<th scope="col">time</th>
									<th scope="col">状态</th>
									<th scope="col">操作</th>
								</tr>
							</thead>
							<tbody>
							    {volist name="data.api" id="api"}
								<tr>
									<td>{$api.id}</td>
									<td>{$api.keywords}</td>
									<td>{$api.chat_title}</td>
									<td>{$api.time}秒</td>
									<td>{if $api.type == 0}停止
                                        {else /} <span style="color:red">推送中 </span>
                                        {/if}
                                        </td>
									<td>
									    {if $api.type == 0}<button class="btn  btn-xs" onclick="update_type({$api.id},1)" >开始</button>
                                        {else /}<button class="btn  btn-xs" onclick="update_type({$api.id},0)" >暂停</button>
                                        {/if}
									    
									    <button class="btn btn-danger btn-xs"  onclick="delete_api({$api.id})">删除</button>
									    </td>
								</tr>
                                {/volist}
							</tbody>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

{include file="public/footer"}

<script>
    function delete_api(id){
        $.get('/delete_corn',{'id':id},function(res){
              if(res.code>0){
                $.notify({
                	icon: 'flaticon-alarm-1',
                	title: '操作提示',
                	message: res.msg,
                },{
                	type: 'info',
                	placement: {
                		from: "bottom",
                		align: "right"
                	},
                	time: 1000,
                });
            }else{

               $.notify({
                	icon: 'flaticon-alarm-1',
                	title: '操作提示',
                	message: res.msg,
                },{
                	type: 'info',
                	placement: {
                		from: "bottom",
                		align: "right"
                	},
                	time: 1000,
                });
                setTimeout(function(){location.reload()},800);
            }
        },'json')
    }
    
    function update_type(id,type){
        $.post('/corn_update',{'id':id,'type':type},function(res){
              if(res.code>0){
                $.notify({
                	icon: 'flaticon-alarm-1',
                	title: '操作提示',
                	message: res.msg,
                },{
                	type: 'info',
                	placement: {
                		from: "bottom",
                		align: "right"
                	},
                	time: 1000,
                });
            }else{

               $.notify({
                	icon: 'flaticon-alarm-1',
                	title: '操作提示',
                	message: res.msg,
                },{
                	type: 'info',
                	placement: {
                		from: "bottom",
                		align: "right"
                	},
                	time: 1000,
                });
                setTimeout(function(){location.reload()},800);
            }
        },'json')
    }
    
    function corn_add(id){
        
        layer.open({
              type: 2,
              title: '设置推送',
              shadeClose: true,
              shade: 0.8,
              area: ['680px', '680px'],
              content: 'corn_add?group_id='+id //iframe的url
            }); 
    }
    

</script>